package org.niit.util

import java.util.Properties
import scala.io.Source

/**
 * 配置工具类，用于加载配置文件
 */
object ConfigUtil {
  // 数据库配置
  val jdbcUrl = "jdbc:mysql://node1:3306/takeaway?useSSL=false&serverTimezone=UTC"
  val jdbcUsername = "root"
  val jdbcPassword = "Niit@123"
  
  // Kafka配置
  val kafkaBootstrapServers = "node1:9092"
  val kafkaGroupId = "takeaway-group"
  val kafkaAutoOffsetReset = "latest"
  val kafkaTopic = "new_takeaway"
  
  // 获取数据库连接属性
  def getJdbcProperties(): Properties = {
    val prop = new Properties()
    prop.setProperty("user", jdbcUsername)
    prop.setProperty("password", jdbcPassword)
    prop.setProperty("driver", "com.mysql.jdbc.Driver")
    prop
  }
  
  // 获取Kafka消费者属性
  def getKafkaProperties(): Properties = {
    val prop = new Properties()
    prop.setProperty("bootstrap.servers", kafkaBootstrapServers)
    prop.setProperty("group.id", kafkaGroupId)
    prop.setProperty("auto.offset.reset", kafkaAutoOffsetReset)
    prop.setProperty("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer")
    prop.setProperty("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer")
    prop
  }
} 